#include <iostream>
#include <vector>
#include <string>
#include <unordered_map>
#include <cmath>

using namespace std;
bool prost(int n) {
    if (n < 100 || n > 999) {
        return false;
    }
    if (n < 2) {
        return false;
    }
    for (int i = 2; i <= sqrt(n); ++i) {
        if (n % i == 0) {
            return false;
        }
    }
    return true;
}

int main() {
    unordered_map<string, int> tacx = {
        {"zero", 0}, {"one", 1}, {"two", 2}, {"three", 3},
        {"four", 4}, {"five", 5}, {"six", 6}, {"seven", 7},
        {"eight", 8}, {"nine", 9}
    };

    vector<string> n(3);
    for (int i = 0; i < 3; ++i) {
        cin >> n[i];
    }

    if (tacx.find(n[0]) == tacx.end() || tacx.find(n[1]) == tacx.end() || tacx.find(n[2]) == tacx.end()) {
        cout << "Wrong input" << endl;
        return 0;
    }

    int number = tacx[n[0]] * 100 + tacx[n[1]] * 10 + tacx[n[2]];

    if (prost(number)) {
        cout << number << endl;
    } else {
        int pright = number;
        while (!prost(pright)) {
            ++pright;
        }

        int pleft = number;
        while (!prost(pleft)) {
            --pleft;
        }

        if (abs(number - pright) <= abs(number - pleft)) {
            cout << pright << endl;
        } else {
            cout << pleft << endl;
        }
    }

    return 0;
}
